package warthog.scangen;

public class StringStrategy extends ScanStrategy {

	public String variables() {
		return 	
				"  private CharSequence yy_buffer;\n"+
				"  private int buflen;\n"
				;
	}

	public String functions(String className) {
			return
					"  void reset(CharSequence input) {\n"+
					"    this.yy_buffer = input;\n"+
					"    buflen = yy_buffer.length();\n"+
					"    start = Start.init;\n"+
					"    left=0; mark=0;\n"+
					"  }\n"+
					"  "+className+"(CharSequence yy_input) { reset(yy_input); }\n"+
					"  public String text() { return yy_buffer.subSequence(left, mark).toString(); }\n"+
					"  public String text(int a, int b) { return yy_buffer.subSequence(left+a, mark-b).toString(); }\n"+
					"  public int length() { return mark-left; }\n"+
					"  public char charAt(int p) { return yy_buffer.charAt(left+p); }\n"
					;
		}

	public String charAt(String index) {
		return "yy_buffer.charAt("+index+")";
	}

	public String boundsTest() {
		return 
				"        if (right >= buflen) {\n"+
				"          if (left==right) break scan; else break token;\n"+
				"        }\n"
				;
	}

	public String preToken() {
		return	"      left=mark;\n";
	}

	public String toss(String thrown) {
		return ((thrown != null) ? "throws "+thrown : "");
	}

	public String bol() {
		return "left==0";
	}

}
